<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title></title>
  <style>
    body {
      background: rgba(100, 145, 250, 0.3);
    }
    canvas {
      box-shadow: 3px 3px 12px rgba(0, 0, 0, 0.5);
    }
  </style>
</head>
<body>
  <canvas id="canvas" width="640" height="480"></canvas>
  <script>
    const canvas = document.getElementById('canvas');
    const ctx = canvas.getContext('2d');
    
    const pic = new Image();
    
    pic.src = '../assets/countrypath.jpg';
    
    // 必须等图像加载完成
    pic.onload = function (){
      canvas.width = this.width;
      canvas.height = this.height;
      ctx.drawImage(this, 0, 0);   // 图像 绘制到画布的位置
    };
    
  </script>
</body>
</html>